package com.invengo.module_check.data.repsitory.offlinedata;

import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.library_db.entity.module_check.offline.BookJson;
import com.invengo.library_db.entity.module_check.ColumBean;
import com.invengo.library_db.entity.module_check.offline.FlowBean;
import com.invengo.library_db.entity.module_check.ShelfBean;
import com.invengo.library_db.entity.module_check.ShelfJson;
import com.invengo.library_db.entity.module_check.StructBean;
import com.invengo.library_db.entity.module_check.offline.UserBean;
import com.invengo.module_check.data.repsitory.offlinedata.source.NetModelSource;
import com.invengo.module_check.data.repsitory.offlinedata.source.impl.HttpNetModelSourceImpl;

import java.util.List;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.bus.SourceUtils;
import me.goldze.mvvmhabit.http.BaseBean;
import me.goldze.mvvmhabit.http.UpdateResult;

public class NetModelRepsitory extends BaseModel<NetModelSource> implements NetModelSource {
    private volatile static NetModelRepsitory INSTANCE = null;

    public static NetModelRepsitory getInstance() {
        if (INSTANCE == null) {
            synchronized (NetModelRepsitory.class) {
                if (INSTANCE == null) {
                    INSTANCE = new NetModelRepsitory();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 刷新源
     */
    @Override
    public void refreshSource() {
        source = SourceUtils.getSource(HttpNetModelSourceImpl.class, HttpNetModelSourceImpl.class);
    }

    /**
     * 获取所有用户
     *
     * @return {@link Observable}<{@link BaseBean}<{@link List}<{@link UserBean}>>>
     */
    @Override
    public Observable<BaseBean<List<UserBean>>> getAllUser() {
        return source.getAllUser();
    }

    /**
     * get结构
     *
     */
    @Override
    public Observable<BaseBean<List<StructBean>>> getStruct() {
        return source.getStruct();
    }
    /**
     * 获取所有图层
     *
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */



    @Override
    public Observable<BaseBean<ShelfJson>> getAllShelf() {
        return source.getAllShelf();
    }

    /**
     * 获取图书计数
     *
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link Long}>>
     */
    @Override
    public Observable<BaseBean<Long>> getBookCount(String beginTime, String endTime) {
        return source.getBookCount(beginTime, endTime);
    }

    /**
     * 获取书本分页数据 山东大学的字段为string，我们自己的用的是int
     *
     * @param pageIndex 页面索引
     * @param pageSize  页面大小
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */
    @Override
    public Observable<BaseBean<BookJson>> getPagingDataOfBook(int pageIndex, int pageSize, String beginTime, String endTime) {
        return source.getPagingDataOfBook(pageIndex,pageSize,beginTime,endTime);
    }
    /**
     * 获取书本分页数据  山东大学的字段为string，我们自己的用的是int
     *
     * @param pageIndex 页面索引
     * @param pageSize  页面大小
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */
    @Override
    public Observable<BaseBean<BookJson>> getPagingDataOfBook(String pageIndex, String pageSize, String beginTime, String endTime) {
        return source.getPagingDataOfBook(pageIndex,pageSize,beginTime,endTime);
    }

    @Override
    public void saveUser2DB(List<UserBean> userBeans) {
        NetModelSource.super.saveUser2DB(userBeans);
    }


    /**
     * 插入自身信息
     *
     * @param shelfInfoBeans 货架信息豆
     * @return boolean
     */
    public boolean insertSelfInfo(List<ShelfBean> shelfInfoBeans) {
        return source.insertSelfInfo(shelfInfoBeans);
    }
    public boolean insertCoumBneas(List<ColumBean> columBeans) {
        return source.insertCoumBneas(columBeans);
    }

    @Override
    public void saveBooks2DB(List<BookBean> bookBeans) {
        NetModelSource.super.saveBooks2DB(bookBeans);
    }

    @Override
    public void cleanUserData() {
        NetModelSource.super.cleanUserData();
    }

    @Override
    public void cleanLayerData() {
        NetModelSource.super.cleanLayerData();
    }

    @Override
    public void cleanBookData() {
        NetModelSource.super.cleanBookData();
    }

    @Override
    public void cleanAllBaseData() {
        NetModelSource.super.cleanAllBaseData();
    }

    @Override
    public void cleanAllBusinessData() {
        NetModelSource.super.cleanAllBusinessData();
    }


    public boolean isHaveOfflineData() {
        return source.isHaveOfflineData() ;
    }

    public Long getBookCountFromDB() {
        return source.getBookCountFromDB();
    }

    public Long getUserCountFromDB() {
        return source.getUserCountFromDB();
    }

    public Long getShelfCountFromDB() {
        return source.getShelfCountFromDB();
    }
    public List<ShelfBean> getAllShelfFromDB(){
        return source.getAllShelfFromDB();
    }

    @Override
    public Integer getBusinessCountFromDB() {
        return NetModelSource.super.getBusinessCountFromDB();
    }

    @Override
    public List<FlowBean> getBusinessData() {
        return source.getBusinessData();
    }

    @Override
    public Observable<BaseBean<UserBean>> checkLogin(String account, String password) {
        return null;
    }

    @Override
    public Observable<BaseBean<UpdateResult>> uploadData(FlowBean bean) {
        return source.uploadData(bean);
    }

    @Override
    public void deleteBusinessBean(FlowBean bean) {
        source.deleteBusinessBean(bean);
    }

    @Override
    public void saveStruct2DB(List<StructBean> collect) {
        source.saveStruct2DB(collect);
    }

    @Override
    public List<StructBean> getStructData() {
        return source.getStructData();
    }

    @Override
    public void removeAllColum() {
        source.removeAllColum();
    }

    @Override
    public Long getAllColumCount() {
        return source.getAllColumCount();
    }

    @Override
    public List<ColumBean> getColumData(StructBean bean) {
        return source.getColumData(bean);
    }

    @Override
    public StructBean getStructByShelf(ShelfBean bea) {
        return source.getStructByShelf(bea);
    }
}
